module.exports = function(grunt) {

    grunt.initConfig({
        //读取json文件
        pkg: grunt.file.readJSON('package.json'),
        concat: {
            js: {
                src: ['src/js/*.js'],
                dest: 'build/js/global.js'
            },
            css: {
                src: ['src/css/*.css'],
                dest: 'build/css/style.css'
            }
        },
        uglify: {
            js: {
                src: 'build/js/global.js',
                dest: 'build/js/global.min.js'
            }
        },
        cssmin: {
            css: {
                src: 'build/css/style.css',
                dest: 'build/css/style.min.css'
            }
        },
        jshint: {
            all: ['./build/js/global.js']
        },
        watch: {
            scripts: {
                files: ['src/js/*.js', 'src/css/*.css'],
                tasks: ['concat', 'jshint', 'cssmin', 'uglify:js']
            },
            livereload: {
                options: {
                    livereload: '<%= connect.options.livereload %>'
                },
                files: [
                    'index.html',
                    'build/css/style.min.css',
                    'build/js/global.min.js'
                ]
            }
        },
        connect: {
            options: {
                port: 9000,
                open: true,
                livereload: 35729,
                // Change this to '0.0.0.0' to access the server from outside
                hostname: 'localhost'
            },
            server: {
                options: {
                    port: 9001,
                    base: './'
                }
            }
        }
    });
    //加载任务插件
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-css');

    //注册任务，执行grunt js 会concat  jshint uglify
    grunt.registerTask('js', ['concat:js', 'jshint', 'uglify:js']);
    //注册任务，执行grunt css 会concat cssmin
    grunt.registerTask('css', ['concat:css', 'cssmin:css']);
    //注册任务，执行grunt  会 css js connect watch
    grunt.registerTask('default', ['css', 'js', 'connect', 'watch']);
};
